package com.wen.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wen.common.pojo.system.Role;
import com.wen.common.pojo.system.RolePermission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    //    -- 根据角色id 查角色		--(角色表)
//    select * from role where role.id = 1
    @Select("select * from cms_role where role.id = #{roleId}")
    Role findRoleById(Long roleId);

    //deleteBatchIds
//    @Delete("delete from cms_role where id in (#{ids})")
//    void deleteBatchIds(@Param("ids") String[] ids);




    //------------------以下相当于中间表(角色权限表) 一个角色可以有多个权限
    @Select("select * from cms_role_permission where role_id = #{roleId}")
    List<RolePermission> getRolePermissionByRoleId(Long roleId);

    @Delete("delete from cms_role_permission where role_id = #{roleId}")
    void delRolePermissionsByRoleId(Long roleId);

    @Insert("insert into cms_role_permission(role_id, permission_id) values(#{roleId}, #{permissionId})")
    void insertRoleAndPermission(@Param("roleId") Long roleId, @Param("permissionId") Long permissionId);
    @Delete("delete from cms_role_permission where permission_id = #{id}")
    void delRolePermissionByPermId(Long id);
}
